package com.crocodile.game17.util;

import com.crocodile.game17.common.LoginUser;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;

public class ContextHolder {

    private static Long userId;

    public static Long getUserId(){
        //获取用户id
        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
        LoginUser principal = (LoginUser) authentication.getPrincipal();
        userId = principal.getUser().getId();

        return userId;
    }
}
